package com.luoluo.dao;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.luoluo.bean.Document;
import com.luoluo.search.SearchTools;

public class DocumentDao extends SqlMapClientDaoSupport {
	public final static byte BY_CONTENT = 0x00;
	public final static byte BY_PATH = 0x01;

	public void insert(Document doc) {
		Long id = (Long) getSqlMapClientTemplate().insert("Document.insert",
				doc);
		doc.setId(id);
		SearchTools.add(doc);
	}

	public void update(Document doc) {
		getSqlMapClientTemplate().update("Document.update", doc);

		SearchTools.update(doc);
	}

	public void delete(Document doc) {
		getSqlMapClientTemplate().delete("Document.delete", doc.getId());
		SearchTools.delete(doc);
	}

	public List select(Long... ids) {
		if (null == ids)
			return null;
		String str = "";
		for (int i = 0; i < ids.length; i++) {
			str += ids[i];
			if (i < ids.length - 1) {
				str += ",";
			}
		}
		if (str.length() == 0)
			return null;
		List list = getSqlMapClientTemplate().queryForList("Document.selectIn",
				str);
		return list;
	}
}
